home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Animator (RU).ifs < prev    next >
Text File  |  2005-03-13  |  11KB  |  382 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Serguei Tarassov
  8. Title=Animator.ru
  9. Description=Imports info from Animator.ru
  10. Site=http://www.arbinada.com
  11. Language=RU
  12. Version=25.10.2004
  13. Requires=3.5.0
  14. Comments=
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program AnimatorRu;
  23.  
  24. const
  25.   STR_WIN = '└α┴ß┬Γ├π─Σ┼σ╞µ╟τ╚Φ╔Θ╩Ω╦δ╠∞═φ╬ε╧∩╨≡╤±╥≥╙≤╘⌠╒⌡╓÷╫≈╪°┘∙┌·█√▄ⁿ▌²▐■▀ ';
  26.   STR_KOI = '■▐α└ß┴÷╓Σ─σ┼⌠╘π├⌡╒Φ╚Θ╔Ω╩δ╦∞╠φ═ε╬∩╧ ▀≡╨±╤≥╥≤╙µ╞Γ┬ⁿ▄√█τ╟°╪²▌∙┘≈╫·┌';
  27.   STR_ISO = '╨≡╤±╥≥╙≤╘⌠╒⌡╓÷╫≈╪°┘∙┌·█√▄ⁿ▌²▐■▀ α╣ß╕ΓÉπâΣ║σ╛µ│τ┐Φ╝ΘÜΩ£δ₧∞¥φºεó∩ƒ';
  28.   STR_DOS = 'Ç üíéóâúäñàÑåªçºê¿ë⌐è¬ï"î¼ì¡Ä«Å»Éα''ß''ΓôπöΣòσûµùτÿΦÖΘÜΩ¢δ£∞¥φ₧εƒ∩';
  29.  
  30. const
  31.   DEBUG_MODE = false;
  32.   DEBUG_FOUND_FILMS_FILENAME = 'Animator_found_results.htm';
  33.   DEBUG_FILM_FILENAME        = 'Animator_film.htm';
  34.   
  35. const
  36.   BaseAddress = 'http://www.animator.ru/';
  37.   BaseAddressFilm = BaseAddress + 'db/';
  38.   
  39. var
  40.   MovieName: string;
  41.  
  42. { Some utils functions }
  43. function KOIToWin(Source: string): string;
  44. var
  45.   i: integer;
  46.   s: string;
  47.   c: char;
  48.   chars: array of char;
  49. begin
  50.   Result := '';
  51.   SetArrayLength(chars, 256);
  52.   for i := 0 to 255 do
  53.     chars[i] := chr(i);
  54.   for i := 1 to length(STR_WIN) do
  55.     chars[ord(copy(STR_WIN, i, 1))] := copy(STR_KOI, i, 1);
  56.   for i := 1 to Length(Source) do
  57.     Result := Result + chars[ord(copy(Source, i, 1))];
  58. end;
  59.  
  60. function WinToKOI(Source: string): string;
  61. var
  62.   i: integer;
  63.   s: string;
  64.   c: char;
  65.   chars: array of char;
  66. begin
  67.   Result := '';
  68.   SetArrayLength(chars, 256);
  69.   for i := 0 to 255 do
  70.     chars[i] := chr(i);
  71.   for i := 1 to length(STR_WIN) do
  72.     chars[ord(copy(STR_KOI, i, 1))] := copy(STR_WIN, i, 1);
  73.   for i := 1 to Length(Source) do
  74.     Result := Result + chars[ord(copy(Source, i, 1))];
  75. end;
  76.  
  77.  
  78. procedure DebugOutput(Value: string);
  79. begin
  80.   if DEBUG_MODE then
  81.     Input('Watch', 'Value', Value);
  82. end;
  83.  
  84. procedure DebugOutputFile(FileName: string; FileText: string);
  85. var
  86.   Log: TStringList;
  87. begin
  88.   if DEBUG_MODE then begin
  89.     Log := TStringList.Create;
  90.     Log.Text := FileText;
  91.     Log.SaveToFile(FileName);
  92.     Log.Free;
  93.   end;
  94. end;
  95.  
  96. procedure ClearString(var Value: string);
  97. begin
  98.   HTMLRemoveTags(Value);
  99.   HTMLDecode(Value);
  100.   Value := StringReplace(Value, #13, '');
  101.   Value := StringReplace(Value, #10, '');
  102.   Value := trim(Value);
  103. end;
  104.  
  105. procedure ClearText(var Value: string);
  106. var
  107.   s: string;
  108. begin
  109.   if length(Value) < 2 then exit;
  110.   Value := trim(Value);
  111.   s := copy(Value, 2, length(Value));
  112.   s := StringReplace(s, '<br>', #13#10);
  113.   s := StringReplace(s, '<BR>', #13#10);
  114.   s := StringReplace(s, '<p>', #13#10#13#10);
  115.   s := StringReplace(s, '<p>', #13#10#13#10);
  116.   Value := copy(Value, 1, 1) + s;
  117.   HTMLRemoveTags(Value);
  118.   HTMLDecode(Value);
  119.   Value := trim(Value);
  120. end;
  121.  
  122. procedure RemoveLastDot(var Value: string);
  123. begin
  124.   if length(Value) > 1 then
  125.     if copy(Value, length(Value), 1) = '.' then begin
  126.       Value := copy(Value, 1, length(Value) - 1);
  127.     end;
  128. end;
  129.  
  130. procedure TrimQuotes(var Value: string);
  131. var
  132.   c: char;
  133. begin
  134.   Value := trim(Value);
  135.   c := copy(Value, 1, 1);
  136.   if (c = '''') or (c = '"') or (c = '½') or (c = '<') then
  137.     Value := copy(Value, 2, length(Value));
  138.   c := copy(Value, length(Value), 1);
  139.   if (c = '''') or (c = '"') or (c = '╗') or (c = '>') then
  140.     Value := copy(Value, 1, length(Value) - 1);
  141. end;
  142.  
  143.  
  144.  
  145. { Pages parsing }
  146.  
  147. const
  148.   FoundLabel = '═αΘΣσφε ';
  149.   NothingFoundLabel = '═Φ≈σπε φσ φαΘΣσφε';
  150.   FoundMovieTitleRef = 'href="index.phtml?p=show_film&fid=';
  151.   FoundMovieYearLabel = '<td';
  152.  
  153. //procedure AnalyzeFoundFilmsPage(URL: string; Params: string);
  154. procedure AnalyzeFoundFilmsPage(URL: string);
  155. var
  156.   Page: TStringList;
  157.     FoundTable, SelectedURL: string;
  158.     pos1, pos2: integer;
  159. begin
  160.   PickTreeClear;
  161.   Page := TStringList.Create;
  162. //  Page.Text := PostPage(URL, Params);
  163.   Page.Text := KOIToWin(GetPage(URL));
  164.   DebugOutputFile(DEBUG_FOUND_FILMS_FILENAME, Page.Text);
  165.   if pos(NothingFoundLabel, Page.Text) = 0 then begin
  166.     pos1 := pos(FoundLabel, Page.Text);
  167.     if pos1 <> 0 then begin
  168.       FoundTable := copy(Page.Text, pos1, length(Page.Text));
  169.       //DebugOutput(FoundTable);
  170.       FoundTable := copy(FoundTable, 1, pos('</td', FoundTable) - 1);
  171.       if pos(FoundMovieTitleRef, FoundTable) > 0 then
  172.         AddFoundMoviesTitles(FoundTable);
  173.     end;
  174.   end;
  175.   Page.Free;
  176.     if PickTreeExec(SelectedURL) then
  177.     AnalyzeFilmPage(SelectedURL);
  178. end;
  179.  
  180.  
  181. procedure AddFoundMoviesTitles(Table: string);
  182. var
  183.     CurName, CurURL, s: string;
  184.     pos2, len: integer;
  185. begin
  186.      PickTreeAdd('Cartoons', '');
  187.   len := length(Table);
  188.   while pos(FoundMovieTitleRef, Table) > 0 do begin
  189.     Table := copy(Table, pos(FoundMovieTitleRef, Table) + length('href="'), len);
  190.     pos2 := pos('"', Table);
  191.     CurURL := copy(Table, 1, pos2 - 1);
  192.     //DebugOutput(CurURL);
  193.     Table := copy(Table, pos('>', Table) + 1, len);
  194.     pos2 := pos('<', Table);
  195.     CurName := copy(Table, 1, pos2 - 1);
  196.     ClearString(CurName);
  197.     Table := copy(Table, pos2 + 1, len);
  198.     //DebugOutput(CurName);
  199.     PickTreeAdd(CurName, BaseAddressFilm + CurURL);
  200.   end;
  201. end;
  202.  
  203.  
  204. const
  205.   FilmImageAnchor = 'src="../film_img';
  206.   FilmTitleAnchor = 'class="FilmName">';
  207.   FilmStudioAnchor = '<span';
  208.   FilmActorsAnchor = 'ετΓ≤≈ΦΓαδΦ';
  209.   FilmDirectorAnchor = '≡σµΦ±±σ≡';
  210.   FilmContentAnchor = 'FilmComments';
  211.  
  212. procedure AnalyzeFilmPage(SelectedURL: string);
  213. var
  214.   Page: TStringList;
  215.     Content, Year, Value, FilmType, Actors, Creators: string;
  216.     pos1, pos2, len: integer;
  217. begin
  218.   Page := TStringList.Create;
  219.   Page.Text := KOIToWin(GetPage(SelectedURL));
  220.   DebugOutputFile(DEBUG_FILM_FILENAME, Page.Text);
  221.   
  222.   SetField(fieldURL, SelectedURL)
  223.  
  224.   len := length(Page.Text);
  225.   Content := Page.Text;
  226.   
  227.   // Picture
  228.   pos1 := pos(FilmImageAnchor, Content);
  229.   if pos1 > 0 then begin
  230.     Content := copy(Content, pos1 + length('src="../'), len);
  231.     pos2 := pos('"', Content);
  232.     Value := BaseAddress + copy(Content, 1, pos2 - 1);
  233.     if Input('═αΘΣσφα Ωα≡≥ΦφΩα Ω ⌠Φδⁿ∞≤', '╟απ≡≤τΦ≥ⁿ Ωα≡≥ΦφΩ≤ ?'#13#10'URL:', Value) then
  234.       GetPicture(Value); // False = do not store picture externally
  235.   end;
  236.  
  237.   // Film title
  238.   pos1 := pos(FilmTitleAnchor, Content);
  239.   Content := copy(Content, pos1 + length(FilmTitleAnchor), len);
  240.   pos2 := pos('<', Content);
  241.   Value := copy(Content, 1, pos2 - 1);
  242.   ClearString(Value);
  243.   TrimQuotes(Value);
  244.   Value := AnsiMixedCase(AnsiLowerCase(Value), ' -.');
  245.   SetField(fieldOriginalTitle, Value);
  246.   SetField(fieldTranslatedTitle, Value);
  247.   Content := copy(Content, pos2, len);
  248.  
  249.   // Type and length
  250.   FilmType := '╨Φ±εΓαφφ√Θ';
  251.   // skip 2 <td>
  252.   Content := copy(Content, pos('<td', Content) + 1, len);
  253.   Content := copy(Content, pos('>', Content) + 1, len);
  254.   Content := copy(Content, pos('<td', Content) + 1, len);
  255.   Content := copy(Content, pos('>', Content) + 1, len);
  256.   pos2 := pos('<td', Content);
  257.   if pos2 < pos(FilmStudioAnchor, Content) then begin
  258.     Content := copy(Content, pos2, len);
  259.     pos2 := pos('</td', Content);
  260.     Value := copy(Content, 1, pos2 - 1);
  261.     HTMLRemoveTags(Value);
  262.     pos1 := pos(',', Value);
  263.     if pos1 > 0 then begin
  264.       FilmType := copy(Value, 1, pos1 - 1);
  265.       ClearString(FilmType);
  266.       Value := copy(Value, pos1 + 1, length(Value));
  267.       if pos('.', Value) > 0 then
  268.         Value := copy(Value, 1, pos('.', Value) - 1);
  269.       ClearString(Value);
  270.       SetField(fieldLength, Value);
  271.     end;
  272.     Content := copy(Content, pos2, len);
  273.     Content := copy(Content, pos('>', Content) + 1, len);
  274.   end;
  275.  
  276.   // Studio
  277.   Content := copy(Content, pos(FilmStudioAnchor, Content), len);
  278.   Content := copy(Content, pos('>', Content) + 1, len);
  279.   pos2 := pos('<', Content);
  280.   Value := copy(Content, 1, pos2 - 1);
  281.   ClearString(Value);
  282.   SetField(fieldSource, Value);
  283.   Content := copy(Content, pos2, len);
  284.   Content := copy(Content, pos('>', Content) + 1, len);
  285.  
  286.   // Year
  287.   Content := copy(Content, pos(',', Content) + 1, len);
  288.   pos2 := pos('π.', Content);
  289.   if pos2 = 0 then
  290.     pos2 := pos('<', Content);
  291.   Value := copy(Content, 1, pos2 - 1);
  292.   ClearString(Value);
  293.   SetField(fieldYear, Value);
  294.   Year := Value;
  295.   Content := copy(Content, pos2, len);
  296.   Content := copy(Content, pos('>', Content) + 1, len);
  297.   
  298.   // Country
  299.   Value := '╤╤╤╨';
  300.   if Year <> '' then
  301.     if StrToInt(Year, 0) >= 1992 then
  302.       Value := '╨ε±±Φ ';
  303.   SetField(fieldCountry, Value);
  304.  
  305.   // Category
  306.   SetField(fieldCategory, '└φΦ∞α÷Φεφφ√Θ');
  307.   
  308.   // Content
  309.   pos2 := pos(FilmContentAnchor, Content);
  310.   if pos2 > 0 then begin
  311.     Content := copy(Content, pos2, len);
  312.     Content := copy(Content, pos('>', Content) + 1, len);
  313.     pos2 := pos('</table', Content);
  314.     Value := copy(Content, 1, pos2 - 1);
  315.     ClearText(Value);
  316.     Value := StringReplace(Value, #13#10#13#10, #13#10);
  317.     SetField(fieldDescription, Value);
  318.     Content := copy(Content, pos2, len);
  319.   end;
  320.  
  321.   // Director
  322.   pos2 := pos(FilmDirectorAnchor, Content);
  323.   if pos2 > 0 then begin
  324.     Content := copy(Content, pos2, len);
  325.     Content := copy(Content, pos('>', Content) + 1, len);
  326.     pos2 := pos('</span', Content);
  327.     Value := copy(Content, 1, pos2 - 1);
  328.     ClearString(Value);
  329.     SetField(fieldDirector, Value);
  330.     Content := copy(Content, pos2, len);
  331.   end;
  332.   
  333.   // Creators and actors
  334.   pos2 := pos('</table', Content);
  335.   Creators := copy(Content, 1, pos2 - 1);
  336.   Content := copy(Content, pos2, len);
  337.   Actors := Creators;
  338.   pos2 := pos(FilmActorsAnchor, Actors);
  339.   if pos2 > 0 then begin
  340.     Actors := copy(Actors, pos2, len);
  341.     Actors := copy(Actors, pos('>', Actors) + 1, len);
  342.     pos2 := pos('</tr', Actors);
  343.     Actors := copy(Actors, 1, pos2 - 1);
  344.     ClearText(Actors);
  345.     Value := Actors;
  346.     ClearString(Value);
  347.     SetField(fieldActors, Value);
  348.   end;
  349.   Creators := StringReplace(Creators,
  350.                             '</td><td class="PersonsList',
  351.                             ': </td><td class="PersonsList');
  352.   ClearText(Creators);
  353.   Creators := StringReplace(Creators, Actors, '');
  354.   Creators := StringReplace(Creators, '≡εδΦ ετΓ≤≈ΦΓαδΦ: ', '');
  355.   Creators := FilmType + #13#10 + Creators;
  356.   Creators := StringReplace(Creators, #13#10#13#10, #13#10);
  357.   SetField(fieldComments, Creators);
  358.   
  359.   Page.Free;
  360.   //DisplayResults;
  361. end;
  362.  
  363. begin
  364.   if CheckVersion(3,5,0) then
  365.   begin
  366.     MovieName := GetField(fieldOriginalTitle);
  367.     if MovieName = '' then
  368.       MovieName := GetField(fieldTranslatedTitle);
  369.  
  370.     if Input('Import from Animator',
  371.              'Enter the title of the movie:', MovieName) then
  372.     begin
  373.       MovieName := WinToKOI(MovieName);
  374.       AnalyzeFoundFilmsPage(BaseAddress +
  375.         'db/index.phtml?cPage=&p=search&SearchMask=1&text=' +
  376.         UrlEncode(MovieName));
  377.     end;
  378.   end else
  379.   ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  380. end.
  381.  
  382.